package fl.android;

import java.io.Serializable;

/**
 * Note Keeps the data for a single note.
 * 
 */
public class Note implements Serializable {

	private int notePosition;
	private int frequency;
	private int voice;
	
	public static enum Voice {
		Sin,
		Saw,
		Square,
		Random
	}

	// 1=sin
	// 2=saw
	// 3=square
	// 4=random

	/**
	 * Note constructor.
	 * 
	 * @param inst
	 *            The instrument, 1=sine, 2=saw, 3=square, 4=random
	 * @param pos
	 *            , the position in time
	 */
	public Note(Voice inst, int pos, int frequency) {
		assert (inst != null && pos > 0);
		voice = inst.ordinal() + 1;
		notePosition = pos;
		this.frequency = frequency;
		assert (voice == inst.ordinal() + 1);
		assert (notePosition == pos);
	}

	/**
	 * 
	 * @return the instrument being used.
	 */
	public int getvoice() {
		return voice;
	}

	/**
	 * 
	 * @return the position in time of this note.
	 */
	public int getNotePosition() {
		return notePosition;
	}

	/**
	 * 
	 * @return the frequency in Hz of this note.
	 */
	public float getFrequency() {
		return 261.626f * (float) Math.pow(2, frequency / 12.) * 2f;
	}
}
